package com.cy.ppj.service.order.impl;

import com.cy.ppj.dao.mapper.order.OrderFinalStatusMapper;
import com.cy.ppj.model.domian.order.OrderFinalStatus;
import com.cy.ppj.model.enums.ThirdSource;
import com.cy.ppj.model.enums.order.GoodsOrderStatus;
import com.cy.ppj.model.enums.order.OrderFinalStatusE;
import com.cy.ppj.service.BaseService;
import com.cy.ppj.service.order.MallOrderStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 订单状态逻辑处理 service
 * @Author tanyilin
 * @Date 2019/3/29 18:06
 */
@Service
public class MallOrderStatusServiceImpl extends BaseService implements MallOrderStatusService {

    @Autowired
    private OrderFinalStatusMapper orderFinalStatusMapper;

    @Override
    public OrderFinalStatusE getOrderFinalStatus(ThirdSource thirdSource, Long productId, String thirdStatus, GoodsOrderStatus goodsOrderStatus) {

        OrderFinalStatusE finalStatus = null;
        switch (thirdSource) {
            case YUNKEDAI:  //云科贷
                switch (thirdStatus) {
                    case "1":
                        if(goodsOrderStatus == GoodsOrderStatus.NO_BUY) {
                            finalStatus = OrderFinalStatusE.APPLYING;
                        }
                        break;
                    case "2":
                        if(goodsOrderStatus == GoodsOrderStatus.NO_BUY) {
                            finalStatus = OrderFinalStatusE.AUDITING;
                        }
                        break;
                    case "3":
                        if(goodsOrderStatus == GoodsOrderStatus.NO_BUY) {
                            finalStatus = OrderFinalStatusE.DECISION_PASS;
                        }
                        if(goodsOrderStatus == GoodsOrderStatus.AUDITING) {
                            finalStatus = OrderFinalStatusE.GOODS_ORDER_AUDITING;
                        }
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_PASS) {
                            finalStatus = OrderFinalStatusE.WITHDRAW_WAIT;
                        }
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_REJECT) {
                            finalStatus = OrderFinalStatusE.GOODS_ORDER_AUDIT_REJECT;
                        }
                        break;
                    case "4":
                        if(goodsOrderStatus == GoodsOrderStatus.NO_BUY) {
                            finalStatus = OrderFinalStatusE.DECISION_REJECT;
                        }
                        break;
                    case "5":
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_PASS) {
                            finalStatus = OrderFinalStatusE.LOANING;
                        }
                        break;
                    case "6":
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_PASS) {
                            finalStatus = OrderFinalStatusE.LOAN_SUCCESS;
                        }
                        break;
                    case "7":
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_PASS) {
                            finalStatus = OrderFinalStatusE.LOAN_FAIL;
                        }
                        break;
                    case "8":
                        if(goodsOrderStatus == GoodsOrderStatus.AUDIT_PASS) {
                            finalStatus = OrderFinalStatusE.REPAY_COMPLETED;
                        }
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }

//        //根据产品查询，该产品定制的订单状态值
//        OrderFinalStatus dbOrderFinalStatus = new OrderFinalStatus();
//        dbOrderFinalStatus.setProductId(productId);
//        dbOrderFinalStatus.setStatus(finalStatus);
//        dbOrderFinalStatus = orderFinalStatusMapper.selectOne(dbOrderFinalStatus);
//        finalStatusText = dbOrderFinalStatus.getStatusText();

//        Map<String, Object> statusMap = new HashMap<>();
//        statusMap.put("finalStatus", finalStatus);
//        statusMap.put("finalStatusText", finalStatus.getText());

        return finalStatus;
    }

}
